package com.wwj.springboot.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wwj
 */
@Controller
@RequestMapping("upload")
public class UploadController {

    @Value("myfile-path")
    private String getPath;

    //上传头像的方法
    @RequestMapping("upload")
    @ResponseBody
    public Map upload(MultipartFile file) throws Exception {
        file.transferTo(new File(getPath+file.getOriginalFilename()));

        String fileName = file.getOriginalFilename();
        System.out.println(fileName);
        //响应信息。code=0表示上传成功，src是图片上传后新的名字
        Map map=new HashMap();
        map.put("code",0);
        map.put("src",fileName);
        return map;
    }





}
